﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProductBom" :model="stateProductBom.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId" :label="$t('message.autotrans._Model_ProductBom_Product')">
            <el-select v-model="stateProductBom.vmModel.Entity.ProductId" disabled clearable>
               <el-option v-for="item in stateProductBom.AllProducts" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ProductName_FormItem" prop="Entity.ProductName" :label="$t('message.autotrans._Model_ProductBom_ProductName')">
            <el-input v-model="stateProductBom.vmModel.Entity.ProductName" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialId_FormItem" prop="Entity.MaterialId" :label="$t('message.autotrans._Model_ProductBom_Material')">
            <el-select v-model="stateProductBom.vmModel.Entity.MaterialId" disabled clearable>
               <el-option v-for="item in stateProductBom.AllMaterials" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialName_FormItem" prop="Entity.MaterialName" :label="$t('message.autotrans._Model_ProductBom_MaterialName')">
            <el-input v-model="stateProductBom.vmModel.Entity.MaterialName" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Qty_FormItem" prop="Entity.Qty" :label="$t('message.autotrans._Model_ProductBom_Qty')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProductBom_Qty')}), trigger: 'blur' }]" >
            <el-input v-model="stateProductBom.vmModel.Entity.Qty" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Unit_FormItem" prop="Entity.Unit" :label="$t('message.autotrans._Model_ProductBom_Unit')">
            <el-input v-model="stateProductBom.vmModel.Entity.Unit" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateTime_FormItem" prop="Entity.CreateTime" :label="$t('message.autotrans._Model_ProductBom_CreateTime')">
            <el-input v-model="stateProductBom.vmModel.Entity.CreateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateTime_FormItem" prop="Entity.UpdateTime" :label="$t('message.autotrans._Model_ProductBom_UpdateTime')">
            <el-input v-model="stateProductBom.vmModel.Entity.UpdateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateBy_FormItem" prop="Entity.CreateBy" :label="$t('message.autotrans._Model_ProductBom_CreateBy')">
            <el-input v-model="stateProductBom.vmModel.Entity.CreateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateBy_FormItem" prop="Entity.UpdateBy" :label="$t('message.autotrans._Model_ProductBom_UpdateBy')">
            <el-input v-model="stateProductBom.vmModel.Entity.UpdateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IsValid_FormItem" prop="Entity.IsValid" :label="$t('message.autotrans._Model_ProductBom_IsValid')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProductBom_IsValid')}), trigger: 'blur' }]" >
            <el-input v-model="stateProductBom.vmModel.Entity.IsValid" disabled clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onCloseProductBom"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProductManagementProductBomDetails;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { productbomApi } from '/@/api/productmanagement/productbom';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProductBom = ref();
const stateProductBom = reactive({
    vmModel: {
	  Entity:{
        ProductId: null,
        ProductName: '',
        MaterialId: null,
        MaterialName: '',
        Qty: null,
        Unit: '',
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
        IsValid: undefined,
        ID:null,
      },

	},
    
    AllProducts: [] as any[],
    AllMaterials: [] as any[],
});

// 取消
const onCloseProductBom = () => {
    closeDialog();
};

// 提交
const onSubmitProductBom = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProductBom.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            productbomApi().edit(stateProductBom.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/ProductManagement/ProductBom/GetProducts',[],false).then(x=>{stateProductBom.AllProducts = x});
    other.getSelectList('/api/ProductManagement/ProductBom/GetMaterialDocs',[],false).then(x=>{stateProductBom.AllMaterials = x});
    if (ci.attrs["wtmdata"]) {
		stateProductBom.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProductBom.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	productbomApi().get(stateProductBom.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProductBom.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

